﻿@using Caltech.Extensions;
@using Role = Caltech.Service.Common.Roles;
@using Area = Caltech.Service.Common.Areas;

@{
    var hasAccess = new Func<Role, bool>((roleName) =>
    {
        var role = Enum.Parse(typeof(Role), ViewBag.RoleName);
        return role == Role.Admin || role == Role.Manager || roleName.HasFlag(role);
    });
}

<div class="navbar navbar-inverse navbar-fixed-top">
    <div class="container">
        <div class="navbar-header">
            <a ui-sref="home" class="navbar-brand">
                <img src="~/Content/images/logo2.jpg" style="height: 45px; margin-top: -12px;"/></a>
        </div>
        <div class="navbar-collapse collapse navbar-left">
            <ul class="nav navbar-nav">
                @if (Utils.HasAccess(Area.Quote))
                { <li ui-sref-active="active"><a tabindex="-1" ui-sref="quote">Quote</a></li> }
                @if (Utils.HasAccess(Area.PO))
                { <li ui-sref-active="active"><a tabindex="-1" ui-sref="po">PO</a></li> }
                @if (Utils.HasAccess(Area.WO))
                { <li ui-sref-active="active"><a tabindex="-1" ui-sref="workOrder">WO</a></li> }
                @if (Utils.HasAccess(Area.Customer))
                { <li ui-sref-active="active"><a tabindex="-1" ui-sref="customer">Customer list</a></li> }
                @if (Utils.HasAccess(Area.Equipment))
                { <li ui-sref-active="active"><a tabindex="-1" ui-sref="equipment">Equipment</a></li> }                                                                                                                                                                    
                @if (Utils.HasAccess(Area.CustomerEquipment))
                { <li ui-sref-active="active"><a tabindex="-1" ui-sref="customerEquipment">Customer equipment</a></li> }
                @if (Utils.HasAccess(Area.Certificate) || Utils.HasAccess(Area.CertificateView))
                { <li ui-sref-active="active"><a tabindex="-1" ui-sref="certificate">Certificate</a></li> }
                @if (Utils.HasAccess(Area.Standard))
                { <li ui-sref-active="active"><a tabindex="-1" ui-sref="standard">Standard</a></li> }
                @if (Utils.HasAccess(Area.User))
                { <li ui-sref-active="active"><a tabindex="-1" ui-sref="user">User</a></li> }
                @if (Utils.HasAccess(Area.Config))
                { <li ui-sref-active="active"><a tabindex="-1" ui-sref="config">Config</a></li> }
            </ul>
        </div>
        <ul class="nav navbar-nav navbar-right">
            <li class="dropdown">
                <a href="#" target="_self" class="dropdown-toggle" data-toggle="dropdown">
                    <i class="glyphicon glyphicon-user"></i> <span>@ViewBag.UserName</span> <b class="caret"></b>
                </a>
                <ul class="dropdown-menu">
                    <li class="dropdown-header">@ViewBag.RoleName</li>
                    <li><a tabindex="-1" href="@Url.Action("Logout")"><i class="glyphicon glyphicon-log-out"></i> Log out</a></li>
                </ul>
            </li>
        </ul>
    </div>
</div>